<?php

/**
 * 我的推荐
 */

namespace app\sale\common;

class UserHasCommon extends \app\member\common\MemberCommon {


    protected function index() {
        $this->pageInfo['name'] = '我的推荐';
        $this->setMeta('我的推荐');
        $this->setCrumb([
            [
                'name' => '我的推荐',
                'url' => url()
            ]
        ]);

        $type = request('get', 'type', 1, 'intval');

        $config = target('sale/SaleConfig')->getConfig();


        $type = $type;
        $max = $type;
        if($max > $config['sale_level']) {
            $max = 1;
        }

        $userList = target('sale/SaleUser')->levelList($this->userInfo['user_id'], $config['sale_level']);

        $saleList = [];
        $saleNames = explode(',', $config['sale_level_name']);

        for ($i = 1; $i <= $config['sale_level']; $i++) {
            $saleList[] = [
                'type' => $i,
                'name' => $saleNames[$i - 1] ? $saleNames[$i - 1] : $i . '级会员',
                'total' => count($userList[$i])
            ];
        }


        $count = $total[$max - 1];
        $pageData = $this->pageData($count, 10, ['type' => $type]);


        if($userList[$max]) {
            $list = array_slice($userList[$max], $pageData['limit'][0], $pageData['limit'][1]);
        }else {
            $list = [];
        }

        $this->assign('pageList', $list);
        $this->assign('page', $pageData['html']);
        $this->assign('type', $type);
        $this->assign('total', $total);
        $this->assign('saleList', $saleList);
        $this->memberDisplay();
    }

}